

	/**
	funkcja wpisujaca wartosc podanej zmiennej w oknie-rodzicu w pole o nazwie <code> pole</code>
	**/
	function wybierz(id,pole){
	
		window.opener.document.getElementById(pole).value = id;
		window.opener.document.getElementById("form").submit();
		self.setTimeout('self.close()', 300);
		}
		
		
	function wybierz_usluge(id,pole){
	
		var a = window.opener.document.getElementById("pozycja").value;
		window.opener.document.getElementById(pole+a).value = id;
		window.opener.document.getElementById("form").submit();
		self.setTimeout('self.close()', 300);
		}
		
		
   /**
   * Funkcja otwierajaca okno popup
   */
   
   function otworz(url,width,height){
		window.open(url, 'nazwa', 'menubar=no,toolbar=no,location=no,directories=no,status=no,width='+width+',height='+height+',scrollbars=yes,resizable=yes,fullscreen=no,channelmode=no').focus();
		 return false;
	}
	
	/**
	* Oblicza sume z pol, przyjmuje referencje do formularza
	* onclick="suma(this.form)"
	*/
	function suma(oForm){
		
		var x = 0;
			
		for(i=0; i<oForm.elements.length; i++){
			if((oForm.elements[i].type == 'text')){
			x = x + Number(oForm.elements[i].value);

			}
		}
	
		oForm.wynik.value = x;

	}
	/**
	* Blokuje klawisz enter (submit formularza)
	* zastosowanie: input type="text" onkeydown="return blockEnter(event);"
	*/
	function blockEnter(evt) {
 	   evt = (evt) ? evt : event;
	    var charCode = (evt.charCode) ? evt.charCode :
	          ((evt.which) ? evt.which : evt.keyCode);
	    if (charCode == 13) {
	        return false;
	    } else {
	        return true;
	    }
	}
	
	function blockEnterAndCount(evt,row,form) {
 	   evt = (evt) ? evt : event;
	    var charCode = (evt.charCode) ? evt.charCode :
	          ((evt.which) ? evt.which : evt.keyCode);
	    if (charCode == 13) {
	    	cenarazyilosc(row,form);
	        return false;
	    } else {
	        return true;
	    }
	}
	
	
	/**
	* Zlicza wartosc pol o id="'suma'+i" w formularzu wynik zwraca do pola o id="suma"
	*/
	function cenarazyilosc(row,form){
		
		var x = 0;
 		var y = 0;
 		var a;
 		a=Number(zmienSeparator(document.getElementById("cena"+row).value,',','.'));
		y = document.getElementById("ilosc"+row).value * a ;
		
		
		document.getElementById("suma"+row).value = zmienSeparator(y.toFixed(2),'.',',');	
		
			for(i=0; i<form.elements.length; i++){	
				if(form.elements[i].id.substring(0,4) == 'suma'){	
					x = x + Number(zmienSeparator(form.elements[i].value,',','.'));
				}
			}

			form.razem.value = zmienSeparator(x.toFixed(2),'.',',');
			
	}
	
	function zmienSeparator(pole,a,b){
	
		var s='';
		if(pole.indexOf(a)>-1){
			s=s.concat(pole.substring(0,pole.indexOf(a)));
			s=s.concat(b);
			s=s.concat(pole.substring(pole.indexOf(a)+1));
		}
		else
			s=pole;
		
		return s;
	}
	
	
		
	function highlightTableRows(tableId) {
		var previousClass = null;
	    var table = document.getElementById(tableId); 
	    var startRow = 0;
	    // workaround for Tapestry not using thead
	    if (!table.getElementsByTagName("thead")[0]) {
		    startRow = 1;
	    }
	    var tbody = table.getElementsByTagName("tbody")[0];
	    var rows = tbody.getElementsByTagName("tr");
	    // add event handlers so rows light up and are clickable
	    for (i=startRow; i < rows.length; i++) {
	        rows[i].onmouseover = function() { previousClass=this.className;this.className = "highlight" };
	        rows[i].onmouseout = function() { this.className=previousClass };
	     
	      /*  rows[i].onclick = function() {
	            var cell = this.getElementsByTagName("td")[0];
	            var link = cell.getElementsByTagName("a")[0];
	            if (link.onclick) {
	                call = link.getAttribute("onclick");
	                if (call.indexOf("return ") == 0) {
	                    call = call.substring(7);
	                } 
	                // this will not work for links with onclick handlers that return false
	                eval(call);
	            } else {
	                location.href = link.getAttribute("href");
	            }
	            this.style.cursor="wait";
	            return false;
	        }  */
	        
	    }
	}
				
